1 00:00:00,140 --> 00:00:05,840 In this lecture, we're going to take a closer look at how to manipulate physics in Roblox Studio by 2 00:00:05,840 --> 00:00:11,540 manipulating the assembly linear velocity property of parts, as well as using a couple constraints. 3 00:00:11,540 --> 00:00:16,160 One is called vector force and the other is called linear velocity. 4 00:00:16,160 --> 00:00:20,750 Before we get started, we should first differentiate between these three things and when you would 5 00:00:20,750 --> 00:00:21,920 want to use them. 6 00:00:21,920 --> 00:00:28,010 If you need to apply a one time initial force on an object, then this is where you would use the assembly 7 00:00:28,010 --> 00:00:36,260 linear velocity property or use a function on base parts called apply impulse to apply a one time force 8 00:00:36,260 --> 00:00:37,640 onto your object. 9 00:00:37,640 --> 00:00:42,950 This of course, will take into account the different properties for your objects, such as the mass 10 00:00:42,950 --> 00:00:47,960 of the object and any type of friction acting upon your object. 11 00:00:47,960 --> 00:00:54,200 And if you need to apply a constant force instead of a one time force on your object, then instead 12 00:00:54,200 --> 00:01:01,130 you would use something called a vector force instance, which will constantly apply a force over and 13 00:01:01,130 --> 00:01:02,480 over on your object. 14 00:01:02,480 --> 00:01:08,120 And since this constantly applies a force, these forces can build up over time, which could result 15 00:01:08,120 --> 00:01:13,040 in very high speeds on your object if you don't have any other forces acting on it. 16 00:01:13,040 --> 00:01:19,250 And then lastly, if you need to have a constant velocity on your object instead of a constant force, 17 00:01:19,250 --> 00:01:26,990 then you would use a linear velocity instance, and this will have your part constantly move at a consistent 18 00:01:26,990 --> 00:01:31,040 velocity, regardless of its mass or its size. 19 00:01:31,040 --> 00:01:37,160 So let's go ahead and first take a look at assembly linear velocity and using a function called apply 20 00:01:37,160 --> 00:01:39,170 impulse on parts. 21 00:01:39,170 --> 00:01:42,560 Every single part in your game is going to have an assembly linear velocity. 22 00:01:42,560 --> 00:01:46,310 And they're also going to have a function to apply an impulse on that part. 23 00:01:46,340 --> 00:01:51,860 Now we can set the assembly linear velocity of a part directly through the property menu. 24 00:01:51,860 --> 00:01:58,160 So no matter what the mass of our object is, if we were to update the value of the assembly linear 25 00:01:58,160 --> 00:02:01,490 velocity to ten, then that's going to be the force applied. 26 00:02:01,490 --> 00:02:03,740 So my mass is currently at 44.8. 27 00:02:03,740 --> 00:02:07,400 And then if I hit enter here, as you can see my part jumped a little bit. 28 00:02:07,400 --> 00:02:13,490 But if I were to decrease the mass, let me enable custom physical properties and set the density all 29 00:02:13,490 --> 00:02:15,350 the way to 0.01. 30 00:02:15,350 --> 00:02:22,100 I'm going to have a very tiny little mass, and you would think that me applying this same force would 31 00:02:22,100 --> 00:02:23,870 mean that my part would jump up higher. 32 00:02:23,870 --> 00:02:25,340 But you're going to be wrong. 33 00:02:25,340 --> 00:02:30,560 It still only jumps the same amount, and that's because we're keeping the assembly linear velocity 34 00:02:30,560 --> 00:02:31,400 the same. 35 00:02:31,400 --> 00:02:37,760 The previous one had an assembly linear velocity of ten or positive ten force in the y axis. 36 00:02:37,760 --> 00:02:42,470 And so also was the force that we applied on this part with a smaller mass. 37 00:02:42,470 --> 00:02:51,050 So the assembly linear velocity is a property that represents the movement of our part in how many studs 38 00:02:51,050 --> 00:02:52,130 per second. 39 00:02:52,130 --> 00:02:59,120 So basically you could think of me applying a force of ten means my part would move ten studs per second 40 00:02:59,120 --> 00:03:00,980 positive in the y axis. 41 00:03:00,980 --> 00:03:05,540 Now of course, we didn't move ten studs because our part still has a mass to it. 42 00:03:05,540 --> 00:03:11,270 And this was also a one time force that was also being pulled back down by gravity. 43 00:03:11,270 --> 00:03:16,490 But if we were to imagine that there was no gravity in the game, there was no friction and I were to 44 00:03:16,490 --> 00:03:23,060 set the assembly linear velocity to ten, my part would be moving ten studs per second in the y axis 45 00:03:23,060 --> 00:03:28,970 or in the positive y direction, because this value actually represents the direction of the force based 46 00:03:28,970 --> 00:03:30,200 on the global axes. 47 00:03:30,200 --> 00:03:35,030 So if I were to apply a positive force on the y axis, it's always going to be up. 48 00:03:35,030 --> 00:03:38,630 It doesn't matter what the orientation of the part is. 49 00:03:38,630 --> 00:03:45,710 Now, setting the assembly linear velocity directly may result in unwanted behavior, because maybe 50 00:03:45,710 --> 00:03:51,800 you want parts that have more mass to move less, while you want to have parts that have little mass 51 00:03:51,800 --> 00:03:52,730 to move more. 52 00:03:52,730 --> 00:03:57,050 Well, if you were to set the assembly linear velocity and always set it to the same value of, let's 53 00:03:57,050 --> 00:04:02,600 say ten in the positive y axis, no matter what the mass of the part is, it's always going to move 54 00:04:02,600 --> 00:04:03,650 the same amount. 55 00:04:03,650 --> 00:04:10,970 So in order to solve that, we can use a function called apply impulse to apply a force on our object. 56 00:04:10,970 --> 00:04:16,730 And that will take into consideration the mass and let's say the friction, uh, that is being applied 57 00:04:16,730 --> 00:04:17,690 on our object. 58 00:04:17,690 --> 00:04:21,290 So I'll make a reference to my physics part in the workspace. 59 00:04:21,290 --> 00:04:23,420 And I can apply an impulse. 60 00:04:23,420 --> 00:04:26,420 And my impulse is going to be a vector 3.nu. 61 00:04:26,420 --> 00:04:30,350 And we'll do let's say a value of ten on the y axis. 62 00:04:30,350 --> 00:04:36,530 Now let me increase the density back to 0.7 so we can get our mass of 44.8. 63 00:04:36,530 --> 00:04:41,900 And if I hit enter, what you're going to notice is that my part didn't move at all, because this was 64 00:04:41,900 --> 00:04:45,890 a very small force that just couldn't stand up against this mass. 65 00:04:45,890 --> 00:04:48,140 It basically didn't move my part at all. 66 00:04:48,140 --> 00:04:54,950 Now, if I were to reduce the density all the way down to 0.01, we should see our part move a little 67 00:04:54,950 --> 00:04:55,130 bit. 68 00:04:55,130 --> 00:04:57,290 So if I hit enter, there we go. 69 00:04:57,290 --> 00:04:59,690 Our part bounced up just a little bit because. 70 00:04:59,820 --> 00:05:02,010 It's basically almost massless. 71 00:05:02,280 --> 00:05:08,730 If I bring the density back to point seven and I apply a greater impulse, let's say an impulse of 500, 72 00:05:08,730 --> 00:05:11,610 then now my part bounces a little bit. 73 00:05:11,610 --> 00:05:18,540 But if I were to swap the density back to 0.01 and apply this impulse, you're going to see that my 74 00:05:18,540 --> 00:05:23,700 part just shot straight up into the air, because it's basically massless. 75 00:05:23,700 --> 00:05:27,150 And we applied a huge force onto that part. 76 00:05:27,240 --> 00:05:34,320 So this function is great for when you need to just apply a one time force on an object in a particular 77 00:05:34,320 --> 00:05:35,250 direction. 78 00:05:35,250 --> 00:05:40,860 And if you need to take into account the mass of your object, if you want to be able to set the linear 79 00:05:40,890 --> 00:05:45,750 velocity directly without having to worry about the mass of the object, maybe you always want it to 80 00:05:45,750 --> 00:05:48,300 move in the same direction, the same amount. 81 00:05:48,300 --> 00:05:52,230 Then you would set the assembly linear velocity property directly. 82 00:05:52,260 --> 00:05:57,480 Now there's another property here called assembly angular velocity, which is basically the exact same 83 00:05:57,480 --> 00:05:58,680 thing as the linear velocity. 84 00:05:58,680 --> 00:06:02,040 But instead this is representing rotational velocity. 85 00:06:02,040 --> 00:06:08,730 So if I want my part to apply a rotational force, let's say a positive rotational force around the 86 00:06:08,730 --> 00:06:11,700 y axis, if I were to do like 100. 87 00:06:12,590 --> 00:06:18,410 As you can see, my part spun a lot and then eventually that force went back down to zero due to friction. 88 00:06:18,440 --> 00:06:23,780 I can also take into account the mass of the object when I'm applying a rotational force. 89 00:06:23,780 --> 00:06:25,190 By using the apply. 90 00:06:25,190 --> 00:06:26,420 I believe it is. 91 00:06:26,420 --> 00:06:27,350 Is it angular? 92 00:06:27,350 --> 00:06:27,590 Yeah. 93 00:06:27,590 --> 00:06:29,960 Apply angular impulse property. 94 00:06:30,770 --> 00:06:36,680 So if I need to apply a rotational force on my object, and I want to keep it consistent across multiple 95 00:06:36,680 --> 00:06:40,490 different objects with different masses, you can set the property directly. 96 00:06:40,490 --> 00:06:45,920 Otherwise, if you need to take into account the mass of your object, then you would want to use the 97 00:06:45,920 --> 00:06:48,140 apply angular impulse function. 98 00:06:48,140 --> 00:06:50,840 So I could apply an angular impulse here. 99 00:06:51,140 --> 00:06:54,980 Let's say uh a value of ten on the x axis. 100 00:06:54,980 --> 00:07:02,060 And if I were to do this it only moves a little bit because, um, we're basically fighting against 101 00:07:02,060 --> 00:07:03,560 this jagged object. 102 00:07:03,560 --> 00:07:05,510 It's not going to be very easy to rotate it. 103 00:07:05,510 --> 00:07:07,430 So let me try maybe a value of 100. 104 00:07:07,430 --> 00:07:07,970 Okay. 105 00:07:07,970 --> 00:07:08,330 There we go. 106 00:07:08,330 --> 00:07:09,320 We got it to flip. 107 00:07:09,920 --> 00:07:15,050 And then if I were to increase the density to like a value of one, make it really heavy and then apply 108 00:07:15,050 --> 00:07:15,950 this force. 109 00:07:15,950 --> 00:07:21,620 As you can see it does absolutely nothing because this object is too heavy to rotate with this current 110 00:07:21,620 --> 00:07:22,550 force that I'm applying. 111 00:07:22,550 --> 00:07:29,150 But if I bump that up and make it a big value now, I'm able to actually spin my object. 112 00:07:29,150 --> 00:07:33,560 And if I have that density, go back down to 0.01 and then apply this force. 113 00:07:34,400 --> 00:07:39,650 My part is gone, because that was just way too much force to apply on such a light object. 114 00:07:39,860 --> 00:07:44,150 All right, the next thing we're going to go ahead and take a look at is going to be a vector force, 115 00:07:44,150 --> 00:07:47,930 which applies a constant force on an assembly. 116 00:07:47,930 --> 00:07:51,560 So I need to add an attachment into my part. 117 00:07:51,590 --> 00:07:54,200 This is going to be where the force is being applied. 118 00:07:54,200 --> 00:07:57,170 And then I can go ahead and add a vector force. 119 00:07:57,170 --> 00:08:01,280 And then I need to define what attachment I need to apply a force at. 120 00:08:01,280 --> 00:08:06,560 Let me go ahead and actually set the force to zero first of all. 121 00:08:06,560 --> 00:08:09,620 So that way it's not going to apply a force right away. 122 00:08:09,620 --> 00:08:14,990 But now I have defined this vector force as applying a force at this attachment. 123 00:08:14,990 --> 00:08:21,680 And currently it's going to apply a force relative to the orientation of my attachment. 124 00:08:21,680 --> 00:08:28,010 So this force vector right here is going to be dependent on what way my attachment is facing. 125 00:08:28,010 --> 00:08:33,560 If I want to instead have this force be applied based on the global axes of the world, then I can just 126 00:08:33,560 --> 00:08:36,980 switch this relative to property to world. 127 00:08:38,020 --> 00:08:43,870 And then let me go ahead and try to apply a force of, let's say, ten on the y axis. 128 00:08:43,870 --> 00:08:50,830 If I do that, you're going to see my arrow appear and it's trying to apply a force of ten on the y 129 00:08:50,830 --> 00:08:53,470 axis, and it's constantly applying this force. 130 00:08:53,470 --> 00:08:57,040 But of course, because my object is too heavy, nothing is happening. 131 00:08:57,070 --> 00:09:00,700 But if I decide to bump up this value a bit more, maybe to 100. 132 00:09:01,420 --> 00:09:03,010 Nothing's going to happen yet. 133 00:09:03,010 --> 00:09:04,600 Maybe I'll try a thousand. 134 00:09:05,330 --> 00:09:06,590 Still nothing. 135 00:09:06,590 --> 00:09:10,010 How about about 10,000? 136 00:09:10,850 --> 00:09:12,530 Okay, there we go. 137 00:09:12,530 --> 00:09:14,900 And now my object is starting to fly away. 138 00:09:14,900 --> 00:09:16,610 And let me bring that value back down. 139 00:09:16,760 --> 00:09:22,280 And eventually I had to get to a point where my force went beyond the force of gravity. 140 00:09:22,280 --> 00:09:23,870 I think the force of gravity. 141 00:09:23,870 --> 00:09:24,530 What is it? 142 00:09:25,840 --> 00:09:26,920 Where can I find. 143 00:09:26,920 --> 00:09:35,110 Okay, gravity is 196.2, so I should be able to overcome gravity when this force here goes beyond that. 144 00:09:35,110 --> 00:09:38,740 So if I set this to 192 or 193. 145 00:09:40,330 --> 00:09:44,590 That actually still might not be enough because my object is too heavy. 146 00:09:44,590 --> 00:09:47,350 So let me try reducing the density. 147 00:09:47,860 --> 00:09:48,370 Okay. 148 00:09:48,370 --> 00:09:49,570 Yeah, there it goes. 149 00:09:49,960 --> 00:09:51,010 A little bit too much force. 150 00:09:51,010 --> 00:09:52,360 Let me bring that back down to zero. 151 00:09:52,360 --> 00:09:53,380 Come back. 152 00:09:53,740 --> 00:10:01,390 But what you should be noticing is that as I am applying this constant force to my objects, it is getting 153 00:10:01,390 --> 00:10:06,010 faster and faster and faster because there's nothing stopping it. 154 00:10:06,010 --> 00:10:09,970 It's constantly applying a force and that force is building upon each other. 155 00:10:10,480 --> 00:10:10,990 All right. 156 00:10:10,990 --> 00:10:16,270 So considering that the amount of force that we need to overcome gravity with is going to be equal to 157 00:10:16,270 --> 00:10:22,060 the mass of the object multiplied by the gravity in our game, uh, we should take into account our 158 00:10:22,060 --> 00:10:23,500 mass, which is 0.64. 159 00:10:23,500 --> 00:10:29,710 And we should multiply that by our gravity, which should give us a value that perfectly counteracts 160 00:10:29,710 --> 00:10:30,130 gravity. 161 00:10:30,130 --> 00:10:35,320 Which means if I were to move this part upwards, it should float in the air because it's fighting against 162 00:10:35,320 --> 00:10:36,880 gravity perfectly. 163 00:10:37,030 --> 00:10:44,260 So 196.2, which is the gravity in the game multiplied by 0.64, which is the mass of our object, will 164 00:10:44,260 --> 00:10:53,020 yield us a value of 125.568, which should be the force required to not have this object fly away, 165 00:10:53,020 --> 00:10:59,110 but be basically still wherever we put it, because it's perfectly balancing out against gravity. 166 00:10:59,110 --> 00:11:02,410 So if we set this to 125.568. 167 00:11:03,350 --> 00:11:05,600 As you can see, nothing is happening. 168 00:11:05,600 --> 00:11:08,060 But as soon as I lift my object up. 169 00:11:08,700 --> 00:11:09,450 Look at that. 170 00:11:09,450 --> 00:11:13,170 Our part is unanchored, but it's floating. 171 00:11:13,170 --> 00:11:19,260 And that's because this vector force is constantly applying a force that's perfectly counteracting gravity, 172 00:11:19,260 --> 00:11:26,160 which means I could take another part like this and I could knock it into my object. 173 00:11:26,190 --> 00:11:28,020 Let me see if I can change this. 174 00:11:28,020 --> 00:11:30,000 Maybe to no, I can't change it to physical. 175 00:11:30,000 --> 00:11:35,130 How could I, how could I knock this object into the other object here if I put. 176 00:11:35,130 --> 00:11:35,790 Okay, there we go. 177 00:11:35,790 --> 00:11:36,750 That kind of worked. 178 00:11:38,080 --> 00:11:43,330 So as you can see now, our object is basically acting like there's no gravity in the game because I 179 00:11:43,330 --> 00:11:49,600 can knock it around and it doesn't matter because this force inside of it is constantly working against 180 00:11:49,600 --> 00:11:50,290 gravity. 181 00:11:50,290 --> 00:11:56,740 This is basically now zero gravity, so any outside force I apply on it, it's going to completely disregard 182 00:11:56,740 --> 00:11:58,810 gravity, which is really, really cool. 183 00:11:58,810 --> 00:12:04,120 Now you keep hearing me use the terms assembly when we're talking about these different properties of 184 00:12:04,120 --> 00:12:05,230 applying mass. 185 00:12:05,230 --> 00:12:08,230 So let's go ahead and learn what an assembly is. 186 00:12:08,230 --> 00:12:12,730 And I think the best way to learn what an assembly is, is by actually going to the official Roblox 187 00:12:12,730 --> 00:12:15,610 documentation and reading what they have to say. 188 00:12:15,820 --> 00:12:22,300 So inside of the Roblox documentation, they state that an assembly is one or more parts welded by a 189 00:12:22,300 --> 00:12:26,860 rigid well constraint, or connected through movable joints like motor six DS. 190 00:12:26,860 --> 00:12:32,290 You can group an assembly of parts in a model container to quickly organize the parts and related objects 191 00:12:32,290 --> 00:12:33,640 as a single asset. 192 00:12:33,640 --> 00:12:39,910 So basically, an assembly is just a bunch of parts that are connected together through welds or other 193 00:12:39,910 --> 00:12:45,070 types of joints that basically act as one big body of objects. 194 00:12:45,070 --> 00:12:50,800 And because you have the possibility of multiple parts being welded to other parts, you also have to 195 00:12:50,800 --> 00:12:56,290 take into account the mass of those other objects as well when you're calculating physics. 196 00:12:56,290 --> 00:13:01,750 So it says from a physics perspective, an assembly is considered a single rigid body, meaning no force 197 00:13:01,750 --> 00:13:06,850 can push or pull the connected parts from each other, and they will move as a single unit. 198 00:13:06,850 --> 00:13:11,170 All forces applied to a specific base part are applied to its assembly. 199 00:13:11,170 --> 00:13:13,090 For instance, base part. 200 00:13:13,120 --> 00:13:18,430 The apply impulse function applies impulse to the assembly at its assembly center of mass. 201 00:13:18,430 --> 00:13:23,500 So if you had one single part not welded to anything else, then the center of mass would obviously 202 00:13:23,500 --> 00:13:25,510 be within the center of the part. 203 00:13:25,510 --> 00:13:30,700 But if you had maybe two parts that were, let's say, ten studs away from each other, welded to each 204 00:13:30,700 --> 00:13:36,790 other, then the center of mass would obviously be within that distance between those two separate parts. 205 00:13:36,790 --> 00:13:42,550 The Roblox documentation states that every assembly has a root part indicated by its assembly root part 206 00:13:42,550 --> 00:13:43,330 property. 207 00:13:43,330 --> 00:13:47,980 This is the part that doesn't move when the motor 60 transforms are updated, as well as the part used 208 00:13:47,980 --> 00:13:51,640 to keep consistent physic replication and network ownership. 209 00:13:51,640 --> 00:13:57,430 You cannot explicitly set the root part, but the following factors affect probability from highest 210 00:13:57,430 --> 00:13:58,570 to lowest. 211 00:13:58,570 --> 00:14:03,670 So the Roblox game engine automatically picks what the root part of an assembly is going to be, and 212 00:14:03,670 --> 00:14:04,990 it does it in this order. 213 00:14:04,990 --> 00:14:09,130 An anchor part will always be assigned as the root part, which makes sense. 214 00:14:09,130 --> 00:14:13,420 Parts with massless set to false take precedent. 215 00:14:13,420 --> 00:14:18,640 Higher root priority values take precedent, and then finally precedence based on the part size with 216 00:14:18,640 --> 00:14:22,180 multipliers for parts with specific names. 217 00:14:22,750 --> 00:14:29,440 So basically parts that have higher masses are going to likely be the parts set as the root part of 218 00:14:29,440 --> 00:14:30,340 the assembly. 219 00:14:30,340 --> 00:14:31,810 Back inside of studio. 220 00:14:31,810 --> 00:14:37,420 If we currently look at the assembly section, you will see the assembly center of mass, which is going 221 00:14:37,420 --> 00:14:45,400 to be the central position of my object, which is why this value also matches the position of my object 222 00:14:45,400 --> 00:14:47,800 and also matches the origin of my object. 223 00:14:47,800 --> 00:14:50,860 And then it also gives the assembly root part. 224 00:14:50,890 --> 00:14:56,860 Now, since this is only one single part, obviously the assembly root part is the part itself. 225 00:14:56,860 --> 00:14:59,800 But let's say I were to duplicate this part. 226 00:15:00,300 --> 00:15:03,420 And I were to call this my physics part number two. 227 00:15:03,420 --> 00:15:06,240 And let's say I made this one super heavy. 228 00:15:06,240 --> 00:15:09,300 Let's increase the density to like ten. 229 00:15:09,300 --> 00:15:11,640 So now I have a mass of 640. 230 00:15:11,790 --> 00:15:15,060 And then let's go ahead and weld. 231 00:15:16,240 --> 00:15:18,490 This part to my other part. 232 00:15:18,490 --> 00:15:21,610 And now this is my assembly of two parts. 233 00:15:21,610 --> 00:15:27,040 And if you take a look at my second part and we were to look at the assembly route part, obviously 234 00:15:27,040 --> 00:15:32,410 now the new assembly route part is going to be my second physics part, because it is much heavier. 235 00:15:32,410 --> 00:15:38,470 And you can also see the total mass of the entire assembly, which includes the mass of this part and 236 00:15:38,470 --> 00:15:40,480 the mass of this part added together. 237 00:15:40,900 --> 00:15:46,630 Now, if I were to add an attachment inside of my first physics part, and then let's say I added another 238 00:15:46,630 --> 00:15:52,030 vector force, and I wanted to start applying forces relative to the world. 239 00:15:52,030 --> 00:15:54,490 And let's go ahead and assign it this attachment. 240 00:15:55,600 --> 00:15:58,930 As you can see, nothing is happening. 241 00:15:58,930 --> 00:16:04,240 And that's because the amount of force I'm applying is not enough to overcome the amount of friction 242 00:16:04,240 --> 00:16:06,850 with the ground due to the weight of this assembly. 243 00:16:06,850 --> 00:16:08,740 So let's actually bump this up a bit more. 244 00:16:08,740 --> 00:16:09,940 How about 10,000? 245 00:16:10,560 --> 00:16:11,190 No. 246 00:16:11,190 --> 00:16:12,300 Doesn't want to work. 247 00:16:12,300 --> 00:16:13,470 Is it still too heavy? 248 00:16:13,470 --> 00:16:16,980 Okay, then how about we do a hundred thousand? 249 00:16:18,660 --> 00:16:19,830 Okay, there we go. 250 00:16:20,040 --> 00:16:20,730 Oh, no. 251 00:16:20,730 --> 00:16:21,510 Come back. 252 00:16:21,510 --> 00:16:21,990 All right. 253 00:16:21,990 --> 00:16:23,790 That was obviously way too much force. 254 00:16:23,790 --> 00:16:26,460 And it was going in that direction we defined in the world. 255 00:16:26,460 --> 00:16:30,480 So let's actually let's swap this relative to the attachment. 256 00:16:30,480 --> 00:16:35,130 So that way when it starts applying the force um, once the force becomes greater enough, this should 257 00:16:35,130 --> 00:16:40,350 start spinning in a circle because it's no longer going to apply the force based on the axes of the 258 00:16:40,350 --> 00:16:40,980 world. 259 00:16:40,980 --> 00:16:44,220 So let's actually try increasing okay. 260 00:16:44,220 --> 00:16:44,910 There we go. 261 00:16:44,910 --> 00:16:48,480 See, now my part is spinning, uh, faster and faster. 262 00:16:48,480 --> 00:16:49,230 I'm. 263 00:16:49,320 --> 00:16:50,670 This is not good. 264 00:16:50,670 --> 00:16:53,190 Let me let me decrease that force. 265 00:16:53,190 --> 00:16:54,060 Okay, there we go. 266 00:16:54,060 --> 00:16:55,350 It's slowed down. 267 00:16:55,620 --> 00:17:00,510 But as you can see, it started spinning in a circle because we're applying the force relative to the 268 00:17:00,510 --> 00:17:01,290 attachment. 269 00:17:01,290 --> 00:17:04,800 And that's going to be based on the orientation of our attachment. 270 00:17:04,800 --> 00:17:10,530 So as we're applying a force our part is obviously going to start rotating because this one's lighter 271 00:17:10,530 --> 00:17:11,520 and this is the heavier part. 272 00:17:11,520 --> 00:17:13,590 It's going to rotate around this part. 273 00:17:13,590 --> 00:17:19,800 And it's going to keep building up force and more force and more force until eventually it spins so 274 00:17:19,800 --> 00:17:24,060 fast that it'll probably let's actually see how fast we can get it to spin. 275 00:17:24,940 --> 00:17:31,540 So this is applying constant force and it's going to get faster and faster and faster until eventually 276 00:17:31,540 --> 00:17:35,890 we might make some kind of particle accelerator or a nuclear bomb or something. 277 00:17:35,890 --> 00:17:39,640 I don't know, but it's going to keep getting faster and faster, faster. 278 00:17:41,500 --> 00:17:43,840 Um, let's actually make it really fast. 279 00:17:43,840 --> 00:17:45,460 Let's apply more force. 280 00:17:47,370 --> 00:17:48,900 How about more force? 281 00:17:50,860 --> 00:17:56,830 And eventually, at this point, we'll get to, uh, a point of no return and we might break the physics 282 00:17:56,830 --> 00:17:57,580 engine. 283 00:17:57,580 --> 00:17:59,860 Hopefully this thing will calm down. 284 00:18:02,210 --> 00:18:04,490 But I don't think it wants to come down. 285 00:18:04,520 --> 00:18:05,330 Uh oh. 286 00:18:06,050 --> 00:18:11,000 But we should basically be noticing is that, of course, it's applying the force relative to the attachment. 287 00:18:11,000 --> 00:18:16,760 And since our second part over here is the bigger, heavier and badder part out of this assembly, that 288 00:18:16,760 --> 00:18:22,550 force is being applied, uh, basically, uh, currently where the attachment is now, we can actually 289 00:18:22,550 --> 00:18:26,690 change where this force is going to be applied if we tick apply at center of mass. 290 00:18:26,690 --> 00:18:32,510 So instead of applying the force at where this attachment is and to demonstrate that, let's move this 291 00:18:32,510 --> 00:18:38,330 detachment way far out like over there because we have apply at center of mass enabled, it's going 292 00:18:38,330 --> 00:18:42,770 to apply the force wherever the center of mass is for this assembly. 293 00:18:42,770 --> 00:18:49,370 And that means if we were to increase the value to like 25,000, actually that's not great enough. 294 00:18:49,370 --> 00:18:51,020 Let's try 30,000. 295 00:18:51,350 --> 00:18:51,890 Nope. 296 00:18:51,890 --> 00:18:53,270 How about 40,000? 297 00:18:54,350 --> 00:18:55,130 50,000. 298 00:18:55,130 --> 00:18:56,000 Okay, there we go. 299 00:18:56,000 --> 00:19:02,450 As you can see, it's no longer going to rotate because it's applying the force at the center of mass 300 00:19:02,450 --> 00:19:03,710 of this assembly. 301 00:19:03,740 --> 00:19:04,670 Pretty cool. 302 00:19:04,910 --> 00:19:10,790 So definitely one of the very useful features of a vector force is because it applies a constant force. 303 00:19:10,790 --> 00:19:17,090 You can manipulate gravity for individual players without having to manipulate the gravity for the entire 304 00:19:17,090 --> 00:19:19,550 workspace or other physics in your game. 305 00:19:19,550 --> 00:19:24,650 For example, if I want to have my player to have reduced gravity and only this particular player, 306 00:19:24,650 --> 00:19:30,830 I can add a vector force to their root part and assign it to some kind of attachment that I've placed 307 00:19:30,830 --> 00:19:32,780 at the center of the root part. 308 00:19:32,780 --> 00:19:37,610 And then I have applied a force or a constant force of 2000 relative to the world. 309 00:19:37,610 --> 00:19:40,610 So it's going to be always upwards that force. 310 00:19:40,610 --> 00:19:47,840 And now when I go and jump, as you can see, it's acting like I'm in a place that has very low gravity. 311 00:19:48,920 --> 00:19:53,990 And then, of course, if I wanted to have zero gravity in the game, then I would need to simply refer 312 00:19:53,990 --> 00:20:01,970 to the total assembly mass and then multiply that according to the gravity in the game, and then set 313 00:20:01,970 --> 00:20:07,550 that value inside of the vector force to basically have no gravity for my player. 314 00:20:08,450 --> 00:20:13,280 The last instance that we're going to take a look at here is going to be the linear velocity, which 315 00:20:13,310 --> 00:20:17,660 applies a constant velocity on an object regardless of its mass. 316 00:20:17,690 --> 00:20:25,160 So instead of needing to apply a constant force, if you need to apply a constant velocity and you want 317 00:20:25,160 --> 00:20:31,010 an assembly to always move at the same constant speed, then this is going to be a useful constraint 318 00:20:31,010 --> 00:20:31,490 for that. 319 00:20:31,490 --> 00:20:35,210 So let me add an attachment into my physics part. 320 00:20:35,780 --> 00:20:37,550 Let me set the attachment. 321 00:20:38,450 --> 00:20:40,040 Right there and then. 322 00:20:40,040 --> 00:20:43,550 Now I can go ahead and define a vector velocity here. 323 00:20:43,550 --> 00:20:45,650 Currently it's set relative to the world. 324 00:20:46,040 --> 00:20:53,420 And then maybe I want my part to always move one stud every single second in the x direction. 325 00:20:53,420 --> 00:20:55,220 So if I apply that force. 326 00:20:55,880 --> 00:20:59,870 Currently nothing is working because there is force limits enabled. 327 00:20:59,870 --> 00:21:05,000 But if I disable that, as you can see, it's going to start moving my object in that direction. 328 00:21:05,000 --> 00:21:08,930 It doesn't care about any physics or anything because we don't have force limits enabled. 329 00:21:08,930 --> 00:21:12,920 And now my object is always going to move one stud every single second. 330 00:21:12,920 --> 00:21:18,170 And of course I can increase the speed to two studs, and then I can increase it to three studs. 331 00:21:18,170 --> 00:21:24,080 And it's going to always constantly apply that force to try and move that direction that we have defined, 332 00:21:24,080 --> 00:21:24,920 which is positive. 333 00:21:24,950 --> 00:21:27,410 Two in the X direction. 334 00:21:27,410 --> 00:21:34,340 And as you can see, it even lifted up the entire mass just to just to go in that particular direction. 335 00:21:34,730 --> 00:21:40,880 Now, an interesting thing about this constraint is if I were to set the vector velocity to zero, and 336 00:21:40,880 --> 00:21:47,240 I have this enabled with no force limits, you can basically now think of this part as anchor. 337 00:21:47,240 --> 00:21:53,150 You can't move it because I've explicitly defined the velocity for this object to always be zero. 338 00:21:53,150 --> 00:21:56,990 So that means even if I were to raise it into the air. 339 00:21:57,520 --> 00:22:01,810 I think I broke the well, actually, no, it's still working. 340 00:22:02,970 --> 00:22:08,730 If you notice, my object is not, uh, actually, it is moving. 341 00:22:09,060 --> 00:22:10,800 It is very slowly moving. 342 00:22:10,800 --> 00:22:12,810 Let me let me move it up a little bit more. 343 00:22:13,970 --> 00:22:17,300 So if I were to do that and then let's say I did that. 344 00:22:21,460 --> 00:22:27,220 Okay, you can basically see that my object is stuck in the air because I've explicitly defined the 345 00:22:27,220 --> 00:22:28,900 vector velocity to be zero. 346 00:22:28,900 --> 00:22:31,330 Now that doesn't affect the angular velocity. 347 00:22:31,330 --> 00:22:36,070 As you can see, it's still kind of rotating around, uh, the point at which this vector velocity is 348 00:22:36,070 --> 00:22:37,060 being applied. 349 00:22:37,060 --> 00:22:42,250 But since I want the vector velocity to be zero, my part is basically now stuck in the air, even though 350 00:22:42,250 --> 00:22:43,270 it's unanchored. 351 00:22:43,270 --> 00:22:45,010 And then maybe I could be like, okay, you know what? 352 00:22:45,010 --> 00:22:51,400 I want to apply a constant velocity upwards, or I want to have a constant velocity and on my object 353 00:22:51,400 --> 00:22:58,150 will always move positive one studs upwards every single second, regardless of even if I change the 354 00:22:58,150 --> 00:22:59,350 mass of this object. 355 00:22:59,350 --> 00:23:04,300 So if I want to make this even heavier, as you can see, it doesn't do anything, it's still moving 356 00:23:04,300 --> 00:23:06,700 at that same velocity if I. 357 00:23:06,850 --> 00:23:07,210 All right. 358 00:23:07,210 --> 00:23:08,500 Actually, I think that's the limit. 359 00:23:08,500 --> 00:23:09,610 Can I make it any higher. 360 00:23:09,610 --> 00:23:09,850 No. 361 00:23:09,850 --> 00:23:10,480 Okay. 362 00:23:10,480 --> 00:23:17,500 So even though the density of my object is 100 and the mass is 6400, it's still moving up at the same 363 00:23:17,500 --> 00:23:18,010 speed. 364 00:23:18,010 --> 00:23:22,000 And even if I were to set the density all the way to 0.01. 365 00:23:22,740 --> 00:23:27,840 Still nothing happens because it is applying a constant force. 366 00:23:27,840 --> 00:23:31,260 It doesn't care about the mass or friction in the game. 367 00:23:31,680 --> 00:23:36,540 There is one last thing I would like to go over in this lecture, which is network ownership. 368 00:23:36,570 --> 00:23:42,630 There were some additional properties that I did not go over in those other constraints. 369 00:23:42,630 --> 00:23:47,190 If you want to learn more about them, there will be articles linked to this lecture that you can go 370 00:23:47,190 --> 00:23:51,660 ahead and take a look at and mess around with those constraint instances a little bit more. 371 00:23:51,660 --> 00:23:55,890 But on the topic of network ownership, I think this is very important to understand. 372 00:23:55,890 --> 00:24:02,370 And network ownership is basically this idea that something has to calculate the physics for unanchored 373 00:24:02,370 --> 00:24:03,000 parts. 374 00:24:03,000 --> 00:24:08,010 Because these two parts are unanchored, they're going to have physics such as gravity and the like 375 00:24:08,010 --> 00:24:08,910 acting upon it. 376 00:24:08,910 --> 00:24:15,540 And in order for the game or the server that is hosting the game to save resources, it will outsource 377 00:24:15,540 --> 00:24:20,970 that computation to any players that are nearby to unanchored parts. 378 00:24:20,970 --> 00:24:26,340 So what I'm going to do is I'm going to launch a one player server and show you exactly how this network 379 00:24:26,340 --> 00:24:27,510 ownership works. 380 00:24:27,630 --> 00:24:30,480 So here I have my view on the client. 381 00:24:30,480 --> 00:24:33,600 And then here I have my view on the server. 382 00:24:33,600 --> 00:24:40,080 And right now by default, because these two unanchored parts are close to my player, my player has 383 00:24:40,080 --> 00:24:47,460 automatically gained network ownership over them, which means my computer is handling the physics calculation 384 00:24:47,460 --> 00:24:51,150 for these parts, and I can replicate that information to the server. 385 00:24:51,150 --> 00:24:55,020 And the server replicates that information back to all the other clients in the game. 386 00:24:55,020 --> 00:25:00,300 Now, this means that if I were to try to move these parts, actually they might be a little bit too 387 00:25:00,300 --> 00:25:01,800 heavy for me to move. 388 00:25:01,800 --> 00:25:05,880 Let me reduce the mass for these objects, okay? 389 00:25:05,880 --> 00:25:08,490 I've reduced the mass for this particular assembly. 390 00:25:08,490 --> 00:25:14,310 And as you can see as I move this object, I'm actually calculating the physics for that on my, uh, 391 00:25:14,310 --> 00:25:20,010 my computer, which is why me interacting with this particular assembly is actually really smooth. 392 00:25:20,040 --> 00:25:23,880 It's because I'm handling the physics and I'm giving that information to the server. 393 00:25:24,030 --> 00:25:29,010 And in the server view, the server also gets to see that I am moving these objects around. 394 00:25:29,850 --> 00:25:36,060 Now, an issue with network ownership or a vulnerability is because I have control over the physics 395 00:25:36,060 --> 00:25:37,590 of this part on my client. 396 00:25:37,590 --> 00:25:44,910 That means there is really nothing stopping me from manipulating the position or the forces being acted 397 00:25:44,910 --> 00:25:46,650 on these parts. 398 00:25:46,920 --> 00:25:51,000 So as an example, what I'm going to do is I'm going to open up the explorer window. 399 00:25:52,040 --> 00:25:55,520 And let me go ahead and select, let's say this part here. 400 00:25:55,520 --> 00:25:57,800 And let me just start moving it with the move tool. 401 00:25:59,890 --> 00:26:01,480 Actually, it's not working, is it? 402 00:26:01,480 --> 00:26:03,190 Because it might be because they're welded. 403 00:26:05,530 --> 00:26:10,360 Okay, so it's a little broken on my client side, but I am moving. 404 00:26:10,360 --> 00:26:14,110 I believe this should be the, uh, part that has. 405 00:26:14,110 --> 00:26:14,440 Okay. 406 00:26:14,440 --> 00:26:14,770 Yeah. 407 00:26:14,770 --> 00:26:19,870 So because this is the, I guess, root part for this assembly, that's why I'm moving. 408 00:26:19,870 --> 00:26:24,340 The other part wasn't working because this is not the root part for the assembly. 409 00:26:24,340 --> 00:26:25,420 This is. 410 00:26:25,420 --> 00:26:32,080 But as I start moving it, what you'll notice is that the server is also seeing those changes of me 411 00:26:32,080 --> 00:26:33,010 moving this part. 412 00:26:33,010 --> 00:26:39,490 I have control over where this part is positioned, or I even have control over the rotation for this 413 00:26:39,490 --> 00:26:40,090 part as well. 414 00:26:40,090 --> 00:26:44,980 So if I start rotating it, you're going to notice that those changes also replicate to the server. 415 00:26:44,980 --> 00:26:48,220 And that's because I have network ownership over this part. 416 00:26:48,550 --> 00:26:54,010 If I want to be able to manually set the network ownership of a part, that's easy to do, there's a 417 00:26:54,010 --> 00:26:55,000 function for that. 418 00:26:55,510 --> 00:27:01,810 So what I'm going to do is in the workspace, I'm going to get my physics part number two, and there's 419 00:27:01,810 --> 00:27:03,760 a function called set network owner. 420 00:27:04,180 --> 00:27:11,860 And to have the network ownership be given to the server and the server alone, I need to pass nothing 421 00:27:11,860 --> 00:27:12,880 or basically nil. 422 00:27:12,880 --> 00:27:14,890 And once I do that and I hit enter. 423 00:27:14,890 --> 00:27:19,810 Now the physics for this part is going to be handled by the server and not my client, which means, 424 00:27:19,870 --> 00:27:24,850 as you can see, I'm no longer able to rotate it and replicate those changes to the server, even if 425 00:27:24,850 --> 00:27:27,280 I were to move this part around. 426 00:27:27,280 --> 00:27:29,890 So let me pull out the move tool and start moving it. 427 00:27:29,890 --> 00:27:32,290 And as you can see, this is not working. 428 00:27:32,290 --> 00:27:37,750 It's being weird on my client, but you can see that the position is not updating on the server at all. 429 00:27:38,690 --> 00:27:44,900 And it's also going to be a little bit wacky because as I move this object, I mean, obviously it's 430 00:27:44,900 --> 00:27:52,190 bugged on my view, but you'll notice that this the physics for this part is not exactly responsive. 431 00:27:52,190 --> 00:27:55,400 And that's because I'm not calculating the physics for it on the client. 432 00:27:55,400 --> 00:28:00,740 The server is so it's being a little bit unresponsive and it's being a little bit slow. 433 00:28:00,740 --> 00:28:02,360 And this kind of sucks. 434 00:28:02,360 --> 00:28:09,860 So this is also the reason as to why even our character models, uh, we have a network ownership over 435 00:28:09,860 --> 00:28:11,870 them, which is why they're really responsive. 436 00:28:11,870 --> 00:28:17,150 If I move them around, I'm actually calculating all the physics for my character model on my client 437 00:28:17,150 --> 00:28:22,400 side, and I'm replicating that information to the server, which means if I were to actually refer 438 00:28:22,400 --> 00:28:23,900 to my character model. 439 00:28:23,900 --> 00:28:29,930 So this is player one and I were to get the character or actually the humanoid root part, I believe. 440 00:28:29,930 --> 00:28:30,080 Yeah. 441 00:28:30,080 --> 00:28:34,640 Let me get the humanoid root part and let me set the network owner to the server. 442 00:28:34,640 --> 00:28:40,040 Once I do that, I have lost control over the physics calculation for my character. 443 00:28:40,040 --> 00:28:46,070 And as I start, oh gosh, it is extremely delayed and unresponsive. 444 00:28:46,070 --> 00:28:52,580 So right now I'm pressing W and it took about a second for it to respond to my input. 445 00:28:53,240 --> 00:28:57,680 And if I were to press spacebar, as you can see, it's really slow. 446 00:28:57,680 --> 00:28:59,300 My player is lagging around. 447 00:28:59,300 --> 00:29:03,230 And that's because I don't have network ownership over my character. 448 00:29:03,230 --> 00:29:04,700 This really sucks. 449 00:29:05,360 --> 00:29:08,570 Of course, I am able to set the network ownership back to my player. 450 00:29:08,570 --> 00:29:15,140 I just need to pass it a player instance so I could do game dot players that player one and update the 451 00:29:15,140 --> 00:29:16,880 network owner for my humanoid report. 452 00:29:16,880 --> 00:29:21,830 And now everything's smooth again, because I have network ownership over the physics of my character 453 00:29:21,830 --> 00:29:27,770 model, I can also set the network ownership to be automatic, again using a function called set network 454 00:29:27,770 --> 00:29:28,970 ownership auto. 455 00:29:28,970 --> 00:29:34,520 So if I do that, then the network ownership for my character is now automatic, which will still be 456 00:29:34,520 --> 00:29:38,810 set to my computer because it's my character model. 457 00:29:38,810 --> 00:29:45,440 But as for like these parts in the workspace, I could do workspace dot physics part two and set the 458 00:29:45,440 --> 00:29:47,240 network ownership back to automatic. 459 00:29:47,240 --> 00:29:52,850 So now it should have alleviated the control over the physics of that part from the server, and it 460 00:29:52,850 --> 00:29:56,450 should have given it to my player because my player is like right next to it. 461 00:29:56,450 --> 00:30:01,430 So now if I start interacting with it, you can see how much more smooth and responsive it is. 462 00:30:02,240 --> 00:30:04,700 You can see that the physics is working just fine. 463 00:30:05,180 --> 00:30:09,080 But if I were to set network ownership back to the server. 464 00:30:10,390 --> 00:30:16,990 Or set network owner, I believe set network, set network owner back to the server and then try interacting 465 00:30:16,990 --> 00:30:17,530 again. 466 00:30:17,830 --> 00:30:21,280 You can see it's really buggy and glitchy and it doesn't work that well. 467 00:30:21,280 --> 00:30:26,110 So network ownership is a really crucial idea to understand when you're making anything in your games 468 00:30:26,110 --> 00:30:32,950 relating to physics, for example, vehicles in your game, the driver of the vehicle should have network 469 00:30:32,950 --> 00:30:39,880 ownership over it, because if it doesn't, you'll likely end up with laggy, unresponsive, and kind 470 00:30:39,880 --> 00:30:43,780 of crappy vehicles that aren't responding to your input that well. 471 00:30:43,780 --> 00:30:50,320 Like if you had the physics solely be calculated by the server, then your vehicles might not even work 472 00:30:50,320 --> 00:30:50,950 at all. 473 00:30:51,250 --> 00:30:57,310 Now, I'm not an expert on physics, but just by learning and experimenting with the assembly linear 474 00:30:57,310 --> 00:31:02,800 velocity of parts, messing around with linear velocities and vector forces, and understanding the 475 00:31:02,800 --> 00:31:08,950 concept of network ownership allows you to really make whatever kind of strange and wacky physics related 476 00:31:08,980 --> 00:31:12,100 type stuff you want in your game, maybe like a Ferris wheel. 477 00:31:12,100 --> 00:31:18,190 Or you could make like a moving platform, or add zero gravity for specific players in your game and 478 00:31:18,190 --> 00:31:19,030 stuff like that. 479 00:31:19,030 --> 00:31:23,920 So if you're interested in learning more about these different instances and how you can use them to 480 00:31:23,920 --> 00:31:29,440 manipulate physics in your game, all the documentation for them will be linked in this lecture, as 481 00:31:29,440 --> 00:31:32,320 well as documentation for a network ownership. 482 00:31:32,320 --> 00:31:36,520 Other than that, I hope you enjoyed this lecture and I will see you next time.